package com.wuerer.bath.Service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.wuerer.bath.Service.BookService;
import com.wuerer.bath.mapper.BookMapper;
import com.wuerer.bath.pojo.BookForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.wuerer.bath.pojo.Book;

import java.util.List;

/**
 * @author admin
 * @version 1.0.0
 * @ClassName BookServiceImpl.java
 * @Description TODO
 * @createTime 2022年10月16日 10:58
 */
@Service
public class BookServiceImpl  extends ServiceImpl<BookMapper, Book> implements BookService {

    @Override
    public boolean addBook(BookForm bookForm) {
        Book book = new Book();
        String name = bookForm.getName();
        int time = bookForm.getTime();
        book.setTime(time);
        if (!StringUtils.isBlank(name)) {
            book.setName(name);
        }
        book.setStartHour(bookForm.getStartHour());
        book.setStartMinute(bookForm.getStartMinute());
        int insert = baseMapper.insert(book);
//        System.out.println(insert);
        return (insert > 0);
    }

    @Override
    public List<Book> list() {
        QueryWrapper<Book> wrapper = new QueryWrapper<>();
        return baseMapper.selectList(wrapper);
    }

    @Override
    public boolean removeByName(String name) {
        QueryWrapper<Book> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("name", name);
        int delete = baseMapper.delete(queryWrapper);
        return delete > 0;
    }
}
